package fx.login;

import beans.Judge;
import dao.DaoJudge;
import fx.Home;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

public class LoginController implements Initializable {

    DaoJudge dao;
    Judge judge;
    private Stage stage;
    private Home application;
    
    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private Button btnLogin;

    @FXML
    private TextField textBjcpId;

    @FXML
    private TextField textPassword;
    
    @FXML
    private Label errorMessage;


    @FXML
    void login(ActionEvent event) {
        if (application == null){
            errorMessage.setText("Hello " + textBjcpId.getText());
        } else {
            if (!application.userLogging(textBjcpId.getText(), textPassword.getText())){
                errorMessage.setText("Username/Password is incorrect");
            }
        }
    }

    public void setApp(Home application) {
        this.application = application;
    }

    @FXML
    void initialize() {
         assert btnLogin != null : "fx:id=\"btnLogin\" was not injected: check your FXML file 'Login.fxml'.";
        assert errorMessage != null : "fx:id=\"errorMessage\" was not injected: check your FXML file 'Login.fxml'.";
        assert textBjcpId != null : "fx:id=\"textBjcpId\" was not injected: check your FXML file 'Login.fxml'.";
        assert textPassword != null : "fx:id=\"textPassword\" was not injected: check your FXML file 'Login.fxml'.";
        Image imageLogin = new Image(getClass().getResourceAsStream("login.png"));
        btnLogin.setGraphic(new ImageView(imageLogin));
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        initialize();
    }

}
